package com.example.myworkers.service.imp;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.myworkers.dao.GrantMapper;
import com.example.myworkers.dao.LaborMapper;
import com.example.myworkers.model.Grant;
import com.example.myworkers.model.Labor;
import com.example.myworkers.model.Record;
import com.example.myworkers.service.LaborService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 编写者：门硕然
 */
@Service
public class LaborServiceImpl extends ServiceImpl<LaborMapper, Labor>
        implements LaborService {
    @Autowired
    private LaborMapper laborMapper;
    @Override
    public int insertLabor(Labor labor) {
        int value=0;
        //id不为0
        if(labor.getLaborid()>=0)
        {
            //不存在相同id则添加
            if(laborMapper.selectOneByLaborid(labor.getLaborid())==null){
                value=laborMapper.insertSelective(labor);
            }
        }else {
            value=-1;
        }
        return value;
    }

    @Override
    public Labor selectLabor(int id) {
        Labor labor=new Labor();
        if (id!=0){
            labor=laborMapper.selectOneByLaborid(id);
        }
        return labor;
    }

    @Override
    public int updateLabor(Labor labor) {
        int value=0;
        //主键不为0
        if(labor.getLaborid()!=0) {
            //主键信息必须存在
            if(laborMapper.selectOneByLaborid(labor.getLaborid())!=null){
                value=laborMapper.updateSelective(labor);
            }
        }
        return value;
    }

    @Override
    public int deleteLabor(int id) {
        int value=0;
        //id不为0
        if(id!=0){
            value=laborMapper.delByLaborid(id);
        }
        return value;
    }
}
